cc.Class({
    extends: cc.Component,
    properties:
    {
        isLongTouch : {
            default : false,
            tooltip : "是否打开长按",
        },
        longTouchTime : {
            default: 2000,
            tooltip : "长按响应时间(单位:（ms/毫秒）)",
            visible() {
                return this.isLongTouch;
            }
        },
        longTouchEvent : {
            default: null,
            tooltip : "长按的响应事件",
            type : cc.Component.EventHandler,
            visible() {
                return this.isLongTouch;
            },
        },
        _typeData : {
            default: 0,
            tooltip : "数据",
            visible() {
                return this.isLongTouch;
            }
        },
        tipsNode : {
        	default: null,
            type : cc.Node
        },
        uiGameMain: //主ui
        {
            default: null,
            type: cc.Node
        },
        incrLv:{//升级动画节点
        	default: null,
            type: cc.Node
        },
    },
      /***
      **  下面的都是临时变量
      ***/
    //触摸状态
    isTouchState : false,
    //触摸时长
    touchTime : 0,
    longTouchCallback : 0,


    // LIFE-CYCLE CALLBACKS:
    ctor()
    {
        //初始化事件
        this.longTouchEvent = new cc.Component.EventHandler();
    },
    
    /**
     * 长按不松,调用执行函数
     */
    _longTouchCallback:function(){
    	this.uiGameMain.getComponent("UiGameMain").getSkillInfo(this._typeData-1);//设置技能详情
    	this.moveRightAction = cc.moveBy(0.3, cc.v2(670, 0)).easing(cc.easeCubicActionIn());
        this.tipsNode.runAction(this.moveRightAction);
    },
    /**
     * 长按结束回调
     * @param {Object} data
     */
    LongTouchCallBack : function(data)
    {
    	this.longTouchCallback = 0;
        console.log("结束长按");
        this.moveLeftAction = cc.moveBy(0.3, cc.v2(-670, 0)).easing(cc.easeCubicActionIn());
        this.tipsNode.runAction(this.moveLeftAction);
    },
	clickCallBack : function(data)
    {
    	
        console.log("单击"+data);
    },
    onLoad () 
    {

        //触摸开始
        this.node.on(cc.Node.EventType.TOUCH_START,function(event){
            this.isTouchState = true;
            this.touchTime = 0;
        },this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL,function(event){//手指在目标区域外离开屏幕,隐藏tips
	        console.log("TOUCH_CANCEL");
            this.isTouchState = false;
            //判断是不是长按
            if(this.isLongTouch)
            {
                if(this.touchTime >= this.longTouchTime)
                {
                    //派发长按事件
                    this.longTouchEvent.emit([this.longTouchEvent.customEventData]);
                    this.touchTime = 0;
                    event.stopPropagation();
                    return;
                }
            }
            this.touchTime = 0;
            event.stopPropagation();
        },this);
        this.node.on(cc.Node.EventType.TOUCH_END,function(event){
        	console.log("TOUCH_END111");
            this.isTouchState = false;
            //判断是不是长按
            if(this.isLongTouch)
            {
                if(this.touchTime >= this.longTouchTime)
                {
                    //派发长按事件
                    this.longTouchEvent.emit([this.longTouchEvent.customEventData]);
                    this.touchTime = 0;
                    event.stopPropagation();
                    return;
                }else{//不是长按,单击,升级技能
            		//console.log(this._typeData);
            		//console.log(this.longTouchTime);
            		this.uiGameMain.getComponent("UiGameMain").addSkillLevel(this._typeData-1);
            		var anmi = this.incrLv.getComponent(cc.Animation);
		            anmi.play("increment_lv_anim");
		            this.uiGameMain.getComponent("UiGameMain").isSkillCanRaise();//刷新技能是否能升级提示动画
            	}
            }
            this.touchTime = 0;
            event.stopPropagation();
        },this);

    },

    start () {
		
    },

    update (dt)
    {
        //触摸计时
        if(this.isTouchState)
        {
            //防止这个数加的很大
            if(this.touchTime > this.longTouchTime)
            {
                this.touchTime = this.longTouchTime;
                //console.log("长按中...");
                if(this.longTouchCallback != 1){//长按后执行一次响应事件
                	this.longTouchCallback = 1;
                	console.log("长按中...");
                	this._longTouchCallback();
                }
            }
            this.touchTime = this.touchTime + dt*1000;
 
        }
    },
});